﻿using CRMBiz;
using CRMWeb.Utilities.Context;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;

namespace CRMWeb.Pages.AM.EzidebitService
{
    public partial class GetPaymentDetailPlusNextPaymentInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                EziDebitService ezidebitservice = new EziDebitService();
                XmlDocument response = ezidebitservice.GetPaymentDetailPlusNextPaymentInfo(WebConfigurationManager.AppSettings["EziDebitDigitalKey"], txtPaymentReference.Text);
                DataSet ds = ConvertXMLtoDataSet(response.InnerXml);
                dtlsCustomerDetails.DataSource = ds.Tables[0];
                dtlsCustomerDetails.DataBind();
                dtsPrimaryDetail.DataSource = ds.Tables[1];
                dtsPrimaryDetail.DataBind();
                Label21.Text = "NextPaymentInfo";
                Label22.Text = "PaymentDetail";
            }
            catch (Exception ex)
            {
                ErrorHandler.saveErrorLog(ex, CMSContext.CurrentUser.MemberName);
            }
        }

        private DataSet ConvertXMLtoDataSet(string response)
        {
            DataSet ds = new DataSet();
            try
            {
                using (StringReader stringReader = new StringReader(response))
                {
                    ds = new DataSet();
                    ds.ReadXml(stringReader);
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.saveErrorLog(ex, CMSContext.CurrentUser.MemberName);
            }
            return ds;
        }
    }
}